
#include "lcd.h"
#include "dev_prv.h"


void lcd_draw_rect(lcd_t *t, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, const uint8_t *color_p)
{
    if(t->draw_rect==NULL)
    {
        dev_err("lcd drv err, no \"draw_rect\" function!");
        return;
    }
    dev_check_p(t->draw_rect, "lcd drv err, no \"draw_rect\" function!");
    t->draw_rect(t,x0,y0,x1,y1,color_p);
}
void lcd_rotation(lcd_t *t, uint16_t angle)
{
    if(t->rotation==NULL)
    {
        dev_err("lcd drv err, no \"rotation\" function!");
        return;
    }
    t->rotation(t, angle);
}
void lcd_set_backlight(lcd_t *t, uint8_t brightness)
{
    led_adjust(&t->backlight,brightness);
}

void lcd_backlight_off(lcd_t *t)
{
    led_off(&t->backlight);
}

void lcd_backlight_on(lcd_t *t)
{
    led_on(&t->backlight);
}

void lcd_dis_on(lcd_t *t)
{
    if(t->cmd==NULL)
    {
        dev_err("lcd drv err, no \"cmd\" function!");
        return;
    }
    t->cmd(t, t->cmd_group.dis_on);
}

void lcd_draw_complete(lcd_t *t)
{
    if(t->draw_end)
        t->draw_end(t);
        
    BaseType_t xHigherPriorityTaskWoken = pdFALSE; 
    xSemaphoreGiveFromISR(t->draw_complete, &xHigherPriorityTaskWoken);
    portYIELD_FROM_ISR(xHigherPriorityTaskWoken);     
}

void lcd_draw_complete_wait(lcd_t *t)
{
    xSemaphoreTake(t->draw_complete, 2000);
}

